IF exists(SELECT * FROM dbo.sysobjects WHERE name='refterStudieEXamensVul' AND xtype='P') 
BEGIN
	DROP PROCEDURE refterStudieEXamensVul
END
GO

CREATE procedure refterStudieEXamensVul
as
insert into refterstudieEXamens(inschrijvingsNr)
select r.inschrijvingsNr from refterStudie as r
left join refterStudieExamens as s
on r.inschrijvingsNr=s.inschrijvingsNr
where s.inschrijvingsNr is null and (r.pwMaDo like '1' or r.pwVr like '1')

update refterStudieExamens
set
w1MaNm=1,
w1DiNM=1,
w1WoNm=1,
w1DoNm=1,
w2MaNm=1,
w2DiNM=1,
w2WoNm=1,
w2DoNm=1,
w3MaNm=1,
w3DiNM=1,
w3WoNm=1,
w3DoNm=1

from refterstudie as r
left join refterStudieEXamens as s
on r.inschrijvingsNr=s.inschrijvingsNr 
where r.pwMaDo like '1'

update refterStudieExamens
set
w1VrNm=1,
w2VrNm=1,
w3VrNm=1
from refterstudie as r
left join refterStudieEXamens as s
on r.inschrijvingsNr=s.inschrijvingsNr 
where r.pwVr like '1'